package com.zhiche.lisa.bms.service.utils;

import com.alibaba.fastjson.JSONObject;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import com.zhiche.lisa.core.utils.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * wms获取指令数据
 * create linbao
 */
@Component
public class WmsUtil {

    @Value("${lisa.wms.url}")
    private String url;

    @Value("${lisa.wms.socketTimeout}")
    private Integer socketTimeout;

    private final String WMS_PARAM = "shipmentGids";

    /**
     * 根据指令号获取数据
     *
     * @param paramJson
     * @return
     */
    public String getWmsDateByOrderCode(String paramJson) {
        if (StringUtils.isBlank(paramJson)) {
            throw new BaseException("参数不能为空");
        }
        JSONObject obj = new JSONObject();
        obj.put(WMS_PARAM, paramJson);
        String strReturn = HttpClientUtil.postJson(url, null, obj.toJSONString(), socketTimeout);
        if (StringUtils.isNotBlank(strReturn)) {
            RestfulResponse<String> restfulResponse = JSONObject.parseObject(strReturn, RestfulResponse.class);
            if (restfulResponse != null) {
                if (restfulResponse.getCode() != 0) {
                    throw new BaseException(restfulResponse.getMessage());
                }
            }
        }
        return null;

    }
}
